var dlHelpCheckedItems;
function getdlHelpData(type) {
    
    var _type
    
    if(type == "0"){
    
       _type = 1;
    
    }else{ _type = 2; }
    
	var startDate = $("#dlHelpStartDate").val();
	var endDate = $("#dlHelpEndDate").val();
    var shuliang = document.getElementById("dlHelpshuliang").options[document.getElementById("dlHelpshuliang").selectedIndex].value;
    var pindao = document.getElementById("dlHelppindao").options[document.getElementById("dlHelppindao").selectedIndex].value;
	//var osID = document.getElementById("dlHelpOS").options[document.getElementById("dlHelpOS").selectedIndex].value;
	var typeID = document.getElementById("dlHelpType").options[document.getElementById("dlHelpType").selectedIndex].value;
	//var marketID = document.getElementById("dlHelpMarket").options[document.getElementById("dlHelpMarket").selectedIndex].value;
	$(".dlHelpChart").html("");
	if (startDate != "" && endDate != "")
	{
		var start = new Date();
		var end = new Date();

		//统计项
		var items = document.getElementsByName("dlHelpCheckbox");
		dlHelpCheckedItems = new Array();
		for(var i=0;i<items.length;i++) {
			if (items[i].checked)
			{
				dlHelpCheckedItems.push(items[i].value);
			}
		}

		if(dlHelpCheckedItems.length > 0) {


			jQuery('#body-wrapper').showLoading();
			start.setFullYear(startDate.substring(0,4), startDate.substring(5,7)-1, startDate.substring(8,10));
			end.setFullYear(endDate.substring(0,4), endDate.substring(5,7)-1 ,endDate.substring(8,10));

			days = parseInt((end - start)/1000/60/60/24)+1;

			var APIurl = "/client/returnversion?staDate="+startDate+"&pd="+days;
	        
            
            if (shuliang != "")
				APIurl += "&shuliang="+shuliang;
			if (pindao != "")
				APIurl += "&pindao="+pindao;
            if (_type != "")
				APIurl += "&type="+_type;

			
			$.ajax({
				type: "GET",
				url: APIurl,
				dataType : "json",
				jsonnp: "callback",
				success:function(data,textStatus){ loaddlHelpData(data,type)}
			});
		}
		else {
			alert("请选择至少一个统计项");
		}

	}
	else {
		alert("请选择时间区域");
	}
}


var dlHelpTabArr, dlHelpDetailArr, dlHelpSumArr, dlHelpDateArr, MainSubTitle;
function loaddlHelpData(data,type) {
	//var osID = document.getElementById("dlHelpOS").options[document.getElementById("dlHelpOS").selectedIndex].value;
	//var typeID = document.getElementById("dlHelpType").options[document.getElementById("dlHelpType").selectedIndex].value;
	//var marketID = document.getElementById("dlHelpMarket").options[document.getElementById("dlHelpMarket").selectedIndex].value;
	var tab = "";
	var startDate = $("#dlHelpStartDate").val();
	var endDate = $("#dlHelpEndDate").val();
	MainSubTitle = startDate.replace(/\//g, "-") + " 至 " + endDate.replace(/\//g, "-");
	jQuery('#body-wrapper').hideLoading();	


	dlHelpTabArr = new Array();
	dlHelpDetailArr = new Array();
	dlHelpSumArr = new Array();
	dlHelpDateArr = new Array();

	
		changeChartType('dlHelp', 'Table');
	
			//显示选择Tab
			genTabsboard("dlHelp", "dlHelpOS", dlHelpTabArr, dlHelpDetailArr, dlHelpSumArr, dlHelpCheckedItems,type);
			//读取数据
            
            //$("#dlHelptitle").html(data['title']+"&nbsp;&nbsp;&nbsp;&nbsp;2012-04-23");
            //读取数据
		
            
           
			
       
			
            //readSummaryData(data, dlHelpDateArr, "type", dlHelpTabArr, dlHelpDetailArr, dlHelpCheckedItems, dlHelpSumArr);
		

			
            
            $("#dlHelpPieTab").hide();
		$("#dlHelpPie").html("");
        
        
        
        changeChartType('dlHelp','Table');
        
        
        divID = "dlHelpTable"
        
        if(type == 0){
            
            
    
    
    $.ajax({
		type: "GET",
		url: "/client/returncontent",
        dataType: "html", 
		success: function(msg){
            
            
            var table = "";
            
            
            table += "<div style=\" overflow:auto;height:500px;border:0px; \"><table style='border:0px;' class='new_silver_table' id='" + divID + "X'><tr style='border:0px;'><td style='border:0px;text-align:left;'>";
    
    sc = "版本:"+data['title']+"&nbsp;&nbsp;更新日期:"+data['date']+"<br /><br /><br /><br />";
    
    table += sc;
            
            
            
            table += msg;
            
            table += "</td></tr></table></div>";
    
    
    
    $("#"+divID).html(table);
            
            
        }
        
        });
        
        
    
    
    

	
        
    }else{
        
        
        
        $.ajax({
		type: "GET",
		url: "/client/returntable",
        dataType: "html", 
		success: function(msg){
            
            
            
            var table = "<div class=\"csv-box-header\"><strong>明细</strong><div class=\"mnum\" style=\"color:#444\"><span><span style=\"display:none;\"><input onclick=\"getCSVData_save('" +divID+ "X');\" type=\"button\"  id=\"createcsv\" value=\"生成csv\" /></span><a href=\"javascript:getCSVData('" +divID+ "X');\" >下载</a></span><a href=\"javascript:getCSVData('" +divID+ "X');\"><img src=\"resources/images/csv.png\" style=\"vertical-align: middle;\" \></a></div></div>";
        
        
        table += "<div style=\" overflow:auto;height:500px; \"><table class='new_silver_table' id='" + divID + "X'><thead><tr>";

    table+="<th>序号</th><th>事件</th>";
    
	table += "</tr></thead><tbody>";
    
    table +=msg;

	table += "</tr></tfoot></table></div>";
    
    $("#"+divID).html(table);
	//tr_hover($(".new_silver_table tr"), "current");
            
            
            
            
            
         
								}
				});
        
       
        
    }
		
        
        
        
		
            
            
          

		
		
	
}






function changedlHelpTab(tabName, optionName) {
	
    
    
    getdlHelpData(tabName);
    
    
    
    
	$(".bitem").removeClass("selbitem");
	$("#dlHelpTab"+tabName).addClass("selbitem");	
    
	
}


